package com.huifaapp.mall.selectImage;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore.Images.Media;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ObtainSystemImage {
	List<String> Pahts = new ArrayList<String>();
	Cursor cursor;
	String columns[] = new String[] { Media.DATA, Media._ID, Media.TITLE, Media.DISPLAY_NAME };

	public List<String> getimage(Context context) {
		cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, columns, null, null, Media.DATE_ADDED + " desc");
		if (cursor != null) {
			while (cursor.moveToNext()) {
				Pahts.add(cursor.getString(cursor.getColumnIndex(Media.DATA)));
			}
		}
		cursor.close();
		Pahts = isFileExists(Pahts);
		return Pahts;
	}

	public List<String> isFileExists(List<String> Pahts) {
		List<String> strings = new ArrayList<String>();
		for (String path : Pahts) {
			if (!new File(path).exists()) {
				strings.add(path);
			}
		}
		Pahts.removeAll(strings);
		return Pahts;
	}
}
